/*
 * Copyright (c) 2018-2999 深圳市阿毛科技有限公司 All rights reserved.
 *
 * https://www.lamyz.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.lam.mall.api.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.annotation.JsonView;
import com.lam.common.base.controller.BaseController;
import com.lam.common.base.domain.Result;
import com.lam.framework.operLog.annotation.Log;
import com.lam.mall.app.vo.NoticeVo;
import com.lam.mall.entity.Notice;
import com.lam.mall.service.NoticeService;

import cn.hutool.core.bean.BeanUtil;

/**
 * @author lam
 */
@RestController
@RequestMapping("/${frontPath}/notice")
@Log(title = "公告管理接口")
public class NoticeApiController extends BaseController {

	@Autowired
    private NoticeService noticeService;

    /**
     * 置顶公告列表接口
     */
    @GetMapping("/topNoticeList")
    @Log(oper = "置顶公告列表信息")
    @JsonView(NoticeVo.NoContent.class)
    public Result getTopNoticeList() {
        List<Notice> noticeList = noticeService.listNoticeCache();
        List<NoticeVo> noticeVoList = BeanUtil.copyToList(noticeList, NoticeVo.class);
        return Result.ok(noticeVoList);
    }

    /**
     * 获取公告详情
     */
    @GetMapping("/info/{id}")
    @Log(oper = "公告详情")
    @JsonView(NoticeVo.WithContent.class)
    public Result getNoticeById(@PathVariable("id") String id) {
        Notice notice = noticeService.getNoticeByIdCache(id);
        NoticeVo noticeVo = BeanUtil.copyProperties(notice, NoticeVo.class);
        return Result.ok(noticeVo);
    }

    /**
     * 公告列表
     */
    @GetMapping("/noticeList")
    @Log(oper = "公告列表信息")
    public Result pageNotice() {
        return Result.ok(getTableData(noticeService.pageNotice()));
    }
}
